package thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadTest {
    public static void main(String[] args) {

//        for (int i = 0; i < 100; i++) {
//            System.out.println("主线程：" + i);
//        }

        // 线程创建方式一
        /*ThreadDemo01 threadDemo01 = new ThreadDemo01();
        threadDemo01.start();*/

        // 线程创建方式二
        /*ThreadDemo02 threadDemo02 = new ThreadDemo02();
        Thread thread = new Thread(threadDemo02);
        thread.start();*/

//        new Thread(() -> {
//            for (int i = 0; i < 100; i++) {
//                System.out.println("主线程：" + i);
//            }
//        }).start();

        // 线程创建方式三
        ThreadDemo03 threadDemo03 = new ThreadDemo03();
        FutureTask<String> stringFutureTask = new FutureTask<>(threadDemo03);
        Thread thread = new Thread(stringFutureTask);
        thread.start();

        String result = null;
        try {
            result = stringFutureTask.get();
            System.out.println("线程返回值：" + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
